package cn.ruituo.adv9;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <作者>
 * @since <版本>
 */
public class BookTest3 {
    public static void main(String[] args) {
        List<Book2> list = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            Book2 b1= new Book2(i, "java核心第" + i + "卷", "邮电出版社", 30 + i);
            for(int j=1;j<=3;j++) {
                b1.getAuthors().add(new Author("Cao "+j,20+j,"第"+j+"副教授"));
            }
            list.add(b1);
        }
        String s = JSON.toJSONString(list);
        System.out.println(s);
        System.out.println(">>>>>>>>>>>>>>>>>>>");
        List<Book2> book2s = JSON.parseObject(s, new TypeReference<List<Book2>>() {
        });
        for(Book2 b2:book2s){
            System.out.println(b2);
            for(Author au:b2.getAuthors()){
                System.out.println(au);
            }
            System.out.println("?>>>>>>>>>>>>>>>>");
        }
    }
}
